<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<html>
<head>
	<base href="<%=basePath%>">
<meta charset="UTF-8">
<link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />

<script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
<script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>
	<script type="text/javascript">
		$(function () {

			delDicValues();

			showDictypeValue();

			duoxuanAndFanxuan();

			toDicValuePage();

			toEditValuePage();
		});

		function delDicValues() {
			$("#deleteDicValueBtn").on("click",function () {
				var delDicValues = $("#tBody input:checked");
				if(delDicValues.size() == 0)
				{
					alert("请选中至少一条数据！");
					return;
				}
				if(confirm("确定要删除吗？"))
				{
					var id="";
					$.each(delDicValues,function (index,delVal) {
						id+="id="+$(delVal).val()+"&";
					});
					id = id.substring(0,id.length-1);
					$.ajax({
						url:"settings/dictionary/dicValue/delValuesByIds.do",
						type:"post",
						data:id,
						success:function (data) {
							if(data.code == 1)
							{
								alert("删除成功！"+data.message);
								window.location.href = "settings/dictionary/value/index.do";
							}else {
								alert(data.message);
							}
						}
					});
				}
			});
		}

		/**
		 * 展示数据字典值
		 */
		function showDictypeValue() {
			$.ajax({
				url:"settings/dictionary/dicValue/index.do",
				type:"get",
				success:function (data) {

					var dataStr = "";
						$.each(data,function (index,obj) {
							if(index%2 ==0)
							{
								dataStr+="<tr class=\"active\">";
							}else {
								dataStr+="<tr>";
							}
							dataStr+="<td><input type=\"checkbox\" value='"+obj.id+"-"+obj.typeCode+"' /></td>";
							dataStr+="<td>"+(index+1)+"</td>";
							dataStr+="<td>"+obj.value+"</td>";
							dataStr+="<td>"+obj.text+"</td>";
							dataStr+="<td>"+obj.orderNo+"</td>";
							dataStr+="<td>"+obj.typeCode+"</td>";
							dataStr+="</tr>";
						});
						$("#tBody").html(dataStr);
				}
			});
		}

		/**
		 * 多选与反选
		 */
		function duoxuanAndFanxuan() {
			$("#t_thead").on("click",function () {
				$("#tBody input[type=checkbox]").prop("click",$("#t_thead").prop("click"));
			});

			$("#tBody").on("click",'input',function () {
				if($("#tBody input[type=checkbox]").size() == $("#tBody input[type=checkbox]:checked").size())
				{
					$("#t_thead").prop("checked",true);
				}else {
					$("#t_thead").prop("checked",false);
				}
			});
		}

		/**
		 * 跳转至新增字典值页面
		 */
		function toDicValuePage() {
			$("#createDicValueBtn").on("click",function () {
				window.location.href="settings/dictionary/DicValue/toDicValuePage.do";
			});
		}

		/**
		 * 跳转至编辑页面
		 */
		function toEditValuePage() {
			$("#editDicValueBtn").on("click",function () {
				if($("#tBody input:checked").size() != 1)
				{
					alert("请选中一条数据进行编辑！");
					return;
				}
				var typeId = $.trim($("#tBody input:checked").val());
				window.location.href="settings/dictionary/Dicvalue/toEditPage.do?id="+typeId;
			})
		}
	</script>
</head>
<body>

	<div>
		<div style="position: relative; left: 30px; top: -10px;">
			<div class="page-header">
				<h3>字典值列表</h3>
			</div>
		</div>
	</div>
	<div class="btn-toolbar" role="toolbar" style="background-color: #F7F7F7; height: 50px; position: relative;left: 30px;">
		<div class="btn-group" style="position: relative; top: 18%;">
		  <button id="createDicValueBtn" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> 创建</button>
		  <button id="editDicValueBtn" type="button" class="btn btn-default"><span class="glyphicon glyphicon-edit"></span> 编辑</button>
		  <button id="deleteDicValueBtn" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-minus"></span> 删除</button>
		</div>
	</div>
	<div style="position: relative; left: 30px; top: 20px;">
		<table class="table table-hover">
			<thead>
				<tr style="color: #B3B3B3;">
					<td><input type="checkbox" id="t_thead"/></td>
					<td>序号</td>
					<td>字典值</td>
					<td>文本</td>
					<td>排序号</td>
					<td>字典类型编码</td>
				</tr>
			</thead>
			<tbody id="tBody">
				<tr class="active">
					<td><input type="checkbox" /></td>
					<td>1</td>
					<td>m</td>
					<td>男</td>
					<td>1</td>
					<td>sex</td>
				</tr>
				<tr>
					<td><input type="checkbox" /></td>
					<td>2</td>
					<td>f</td>
					<td>女</td>
					<td>2</td>
					<td>sex</td>
				</tr>
				<tr class="active">
					<td><input type="checkbox" /></td>
					<td>3</td>
					<td>1</td>
					<td>一级部门</td>
					<td>1</td>
					<td>orgType</td>
				</tr>
				<tr>
					<td><input type="checkbox" /></td>
					<td>4</td>
					<td>2</td>
					<td>二级部门</td>
					<td>2</td>
					<td>orgType</td>
				</tr>
				<tr class="active">
					<td><input type="checkbox" /></td>
					<td>5</td>
					<td>3</td>
					<td>三级部门</td>
					<td>3</td>
					<td>orgType</td>
				</tr>
			</tbody>
		</table>
	</div>
	
</body>
</html>